package com.skplanet.oneplusonewindow.moim;

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ActivityRunPlugin extends CordovaPlugin {
	public CallbackContext callbackContext;
	public static int REQUEST_CODE1 = 1;
	private static final int ZBAR_SCANNER_REQUEST = 0;

    //cordova.exec(startActivityOK, startActivityFail, "ActivityRunPlugin", "startQRCodeActivity", [] ) calls this function
	@Override
	public boolean execute(String action, JSONArray args,
			CallbackContext callbackContext) throws JSONException {
		this.callbackContext = callbackContext;

		Log.i("CHAT", "hmmm");		
		user.getInstance().setname(args.getString(0));
		user.getInstance().setMiom_id(args.getInt(1));
		
		if("chatAction".equals(action)){
			Context context = this.cordova.getActivity().getApplicationContext();
			Intent intent = new Intent(context, MainActivity.class);
			Log.i("CHAT", "action");
            
            //opens itnent
			this.cordova.startActivityForResult(this, intent, ZBAR_SCANNER_REQUEST);
	        
			return true;
		}
		return false;
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		
	} // onActivityResult

}
